package com.lab303.powerproject.util;

import com.lab303.powerproject.pojo.CustomAtlasDevice;

import java.util.*;

public class AdjustCoordinator {


    public static List adjustByAngle(float startX ,float startY , float endX ,float endY ,double length,double horizontalLength,double verticalLength){
        List<float[]> list = new ArrayList<>();
        System.out.print("调整前["+startX+","+startY+"]----->["+endX+","+endY+"]");
        double angle = 0;
        if (startX!=endX&&startY!=endY)
            angle = Math.atan(Math.abs(endY - startY) / Math.abs(endX - startX));
        if (endX>startX&&endY>startY){  //一象限
            startX+=Math.cos(angle)*length;
            startY+=Math.sin(angle)*length;
            endX-=Math.cos(angle)*length;
            endY-=Math.sin(angle)*length;
        }
        if (endX<startX&&endY>startY){  //二象限
            startX-=Math.cos(angle)*length;
            startY+=Math.sin(angle)*length;
            endX+=Math.cos(angle)*length;
            endY-=Math.sin(angle)*length;
        }
        if (endX<startX&&endY<startY){  //三象限
            startX-=Math.cos(angle)*length;
            startY-=Math.sin(angle)*length;
            endX+=Math.cos(angle)*length;
            endY+=Math.sin(angle)*length;
        }
        if (startX<endX&&startY>endY){  //四象限
            startX+=Math.cos(angle)*length;
            startY-=Math.sin(angle)*length;
            endX-=Math.cos(angle)*length;
            endY+=Math.sin(angle)*length;
        }
        if (startX==endX){
            if (startY<endY){
                endY-=verticalLength;
                startY+=(verticalLength-10);
            }else {
                endY+=verticalLength;
                startY-=(verticalLength-10);
            }
        }
        if (startY==endY){
            if (startX>endX){
                endX+=horizontalLength;
                startX-=(horizontalLength-10);
            }else {
                endX-=horizontalLength;
                startX+=(horizontalLength-10);
            }
        }
        System.out.print("                 调整后["+startX+","+startY+"]----->["+endX+","+endY+"]");
        System.out.println();
        float[] start = new float[]{startX,startY};
        float[] end = new float[]{endX,endY};
        list.add(start);
        list.add(end);
        return list;
    }

    public static void main(String[] args) {
        double atan = Math.atan(Math.sqrt(3));
        double cos = Math.cos(atan);
        System.out.println(cos);
    }

    public static double getLength(List<CustomAtlasDevice> list){
        Iterator<CustomAtlasDevice> iterator = list.iterator();
        float maxHigh = Float.MIN_VALUE;
        while (iterator.hasNext()){
            CustomAtlasDevice next = iterator.next();
            maxHigh = Math.max(maxHigh,next.getCoordinate()[1]);
        }
        System.out.println("最大高度差:"+maxHigh);
        return maxHigh/800*25;
    }
}
